<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Global env</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../process/reference.html#header.boost.process.env_hpp" title="Header &lt;boost/process/env.hpp&gt;">
<link rel="prev" href="cmd.html" title="Global cmd">
<link rel="next" href="basic_environment.html" title="Class template basic_environment">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmd.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.env_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="basic_environment.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="boost.process.env"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Global env</span></h2>
<p>boost::process::env</p>
</div>
<h2 xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv-title">Synopsis</h2>
<div xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../process/reference.html#header.boost.process.env_hpp" title="Header &lt;boost/process/env.hpp&gt;">boost/process/env.hpp</a>&gt;

</span><span class="emphasis"><em><span class="identifier">unspecified</span></em></span> env<span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.31.9.8.6.4"></a><h2>Description</h2>
<p>The <code class="computeroutput">env</code> property provides a functional way to modify the environment used by the child process. If none is passed the environment is inherited from the father process. Appending means that the environment will be interpreted as a ';' or ':' separated list as used in <code class="computeroutput">PATH</code>.</p>
<p>On both <code class="computeroutput">posix</code> and <code class="computeroutput">windows</code> the environment variables can be lists of strings, separated by ';'. This is typically used for the <code class="computeroutput">PATH</code> variable.</p>
<p>By default the environment will be inherited from the launching process, which is also true if environment are modified with this initializer.</p>
<div class="sect1">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="namespaceboost_1_1process_1env_details"></a>Details</h2></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect2"><a href="env.html#namespaceboost_1_1process_1env_operations">Operations</a></span></dt>
<dt><span class="sect2"><a href="env.html#namespaceboost_1_1process_1env_example">Example</a></span></dt>
</dl></div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="namespaceboost_1_1process_1env_operations"></a>Operations</h3></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_set_var">Setting variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_append_var">Append variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_reset">Reset variables</a></span></dt>
<dt><span class="sect3"><a href="env.html#namespaceboost_1_1process_1env_init">Initialize the environment</a></span></dt>
</dl></div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_set_var"></a>Setting variables</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_set_var_value">value</a></span></dt>
</dl></div>
<p>To set a variable <code class="computeroutput">id</code> the value <code class="computeroutput">value</code> the following syntax can be used.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">value</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="identifier">value</span><span class="special">)</span><span class="special">;</span>
</pre>
<p><code class="computeroutput">std::initializer_list</code> is among the allowed types, so the following syntax is also possible.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Creates the variable if it does not exist.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code> for both <code class="computeroutput">id</code> and <code class="computeroutput">value</code>.</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_set_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::initializer_list&lt;const char_type *&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::vector&lt;std::basic_string&lt;char_type&gt;&gt;</code></p></li>
</ul></div>
<p>
</p>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Using <code class="computeroutput">std::vector</code> or <code class="computeroutput">std::initializer_list</code></p></td></tr>
</table></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_append_var"></a>Append variables</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_append_var_id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_append_var_value">value</a></span></dt>
</dl></div>
<p>Appending means, that a variable will be interpreted as a To append a variable <code class="computeroutput">id</code> the value <code class="computeroutput">value</code> the following syntax can be used:</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">+=</span> <span class="identifier">value</span><span class="special">;</span>
</pre>
<p><code class="computeroutput">std::initializer_list</code> is among the allowed types, so the following syntax is also possible.</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">+=</span> <span class="special">{</span><span class="identifier">value1</span><span class="special">,</span> <span class="identifier">value2</span><span class="special">}</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>Creates the variable if it does not exist.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code> for both <code class="computeroutput">id</code> and <code class="computeroutput">value</code>.</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_append_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_append_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::initializer_list&lt;const char_type *&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">std::vector&lt;std::basic_string&lt;char_type&gt;&gt;</code></p></li>
</ul></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_reset"></a>Reset variables</h4></div></div></div>
<div class="toc"><dl class="toc"><dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_reset_var_id">id</a></span></dt></dl></div>
<p>Reseting signle variables can be done in the following way:</p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">[</span><span class="identifier">id</span><span class="special">]</span> <span class="special">=</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">id</span><span class="special">,</span> <span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>This does not set the value empty, but removes it from the list.</p></td></tr>
</table></div>
<p>
The following lists contain possible value types, with <code class="computeroutput">char_type</code> being either <code class="computeroutput">char</code> or <code class="computeroutput">wchar_t</code>:</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_reset_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
</div>
<div class="sect3">
<div class="titlepage"><div><div><h4 class="title">
<a name="namespaceboost_1_1process_1env_init"></a>Initialize the environment</h4></div></div></div>
<div class="toc"><dl class="toc">
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_init_var_id">id</a></span></dt>
<dt><span class="sect4"><a href="env.html#namespaceboost_1_1process_1env_init_var_value">value</a></span></dt>
</dl></div>
<p>The whole environment can be initialized from an object of type  <a class="link" href="../../process/reference.html#boost.process.environment">boost::process::environment</a> </p>
<pre class="programlisting"><span class="identifier">env</span><span class="special">=</span><span class="identifier">env</span><span class="special">;</span>
<span class="identifier">env</span><span class="special">(</span><span class="identifier">env</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="note"><table border="0" summary="Note">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../doc/src/images/note.png"></td>
<th align="left">Note</th>
</tr>
<tr><td align="left" valign="top"><p>The passed <code class="computeroutput">environment</code> can also be default-constructed to get an empty environment.</p></td></tr>
</table></div>
<p>
</p>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_init_var_id"></a>id</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p><code class="computeroutput">std::basic_string&lt;char_type&gt;</code></p></li>
<li class="listitem"><p><code class="computeroutput">const char_type *</code></p></li>
</ul></div>
<p>
</p>
</div>
<div class="sect4">
<div class="titlepage"><div><div><h5 class="title">
<a name="namespaceboost_1_1process_1env_init_var_value"></a>value</h5></div></div></div>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "><li class="listitem"><p><code class="computeroutput"><a class="link" href="basic_environment.html" title="Class template basic_environment">boost::process::basic_environment</a>&lt;char_type&gt;</code></p></li></ul></div>
<p>
</p>
</div>
</div>
</div>
<div class="sect2">
<div class="titlepage"><div><div><h3 class="title">
<a name="namespaceboost_1_1process_1env_example"></a>Example</h3></div></div></div>
<pre class="programlisting"><span class="identifier">spawn</span><span class="special">(</span><span class="string">"b2"</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"PATH"</span><span class="special">]</span><span class="special">+=</span><span class="string">"F:/boost"</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"SOME_VAR"</span><span class="special">]</span><span class="special">=</span><span class="identifier">boost</span><span class="special">::</span><span class="identifier">none</span><span class="special">,</span> <span class="identifier">env</span><span class="special">[</span><span class="string">"NEW_VAR"</span><span class="special">]</span><span class="special">=</span><span class="string">"VALUE"</span><span class="special">)</span><span class="special">;</span>
</pre>
<p>If the overload style should be done by passing an instance of  <a class="link" href="../../process/reference.html#boost.process.environment">boost::process::environment</a>  the above example would look like this.</p>
<pre class="programlisting"><span class="identifier">environment</span> <span class="identifier">e</span> <span class="special">=</span> <span class="identifier">this_process</span><span class="special">::</span><span class="identifier">environment</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">[</span><span class="string">"PATH"</span><span class="special">]</span>   <span class="special">+=</span> <span class="string">"F:/boost"</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">.</span><span class="identifier">erase</span><span class="special">(</span><span class="string">"SOME_VAR"</span><span class="special">)</span><span class="special">;</span>
<span class="identifier">e</span><span class="special">[</span><span class="string">"NEW_VAR"</span><span class="special">]</span> <span class="special">=</span> <span class="string">"VALUE"</span><span class="special">;</span>
<span class="identifier">spawn</span><span class="special">(</span><span class="string">"b2"</span><span class="special">,</span> <span class="identifier">e</span><span class="special">)</span><span class="special">;</span>
</pre>
<div class="warning"><table border="0" summary="Warning">
<tr>
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Warning]" src="../../../../doc/src/images/warning.png"></td>
<th align="left">Warning</th>
</tr>
<tr><td align="left" valign="top"><p>Passing an empty environment will cause undefined behaviour. </p></td></tr>
</table></div>
<p>
</p>
</div>
</div>
</div>
</div>
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
<td align="left"></td>
<td align="right"><div class="copyright-footer">Copyright © 2006-2012 Julio M. Merino Vidal, Ilya Sokolov,
      Felipe Tanus, Jeff Flinn, Boris Schaeling<br>Copyright © 2016 Klemens D. Morgenstern<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
      </p>
</div></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="cmd.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../process/reference.html#header.boost.process.env_hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="basic_environment.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
